## -*- coding: utf-8 -*-
<%inherit file="/base/base_with_nav.html"/>

<div class="span-24">
  <div class="span-24">
    <div class="span-18">
      <div id="bannerWrapper">
          <img src="${h.url_for('/images/banner1.jpg')}" />
      </div>
    </div>
    <div class="span-6 last">
      <div id="signupWrapper" style="padding-top:5px;">
      <%include file="/component/user_nav.html"/>     
      </div>
    </div>
  </div>
  <div class="span-24">
  ${next.body()}
  </div>
</div>

<%! import datetime %>
<%def name="head()">
  ${parent.head()}
  ${h.stylesheet_link(h.url_for('/css/signup.css'))}
  ${h.javascript_link(h.url_for('/js/jquery.form.js'))}
  ${h.javascript_link(h.url_for('/js/jquery.validate.min.js'))}
  ${h.javascript_link(h.url_for('/js/jquery.delay.js'))}

  <script type="text/javascript">	  
  $.validator.addMethod('registerName', function (value) {
	    return /^([a-z]|\d|-)+$/.test(value);
	}, '注册名只能包含小写英文字符，数字和中划线');

  
  $(document).ready(function() {
	  $("#signupform").validate({
	    rules: {
		  userName: {
		    required: true,
		    rangelength: [2, 15],
		    registerName: true
		  },
		  password: {
		    required: true,
		    rangelength: [3, 15]
		  }
	    },
		messages: {
	      userName: {
		    required: "请提供注册名",
		    rangelength: jQuery.format("请输入{0}到{1}个字符")
          },
		  password: {
			required: "请提供密码",
			rangelength: jQuery.format("请输入{0}到{1}位密码")
		  }
		},
		errorPlacement: function(error, element) {
			error.appendTo( element.parent("td").parent("tr").next("tr").children("td")[1] );
			//error.appendTo($('#errorWrapper'));
		},
		// specifying a submitHandler prevents the default submit, good for the demo
		submitHandler: function() {
		      $.post("${h.url_for_www(controller='account', action='log_in')}",
		        {userName:$('#userName').val(), 
                 password:$('#password').val(),
                 section_id: '${c.section_id}' },
		        showResponse, 
		        "json");
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
		  // set &nbsp; as text for IE
		  //label.html("&nbsp;").addClass("checked").appendTo(label.parent("td").parent("tr").prev("tr").children("td")[1]);
		  label.remove();
		}
	  });
    
    $('#btnRegister').click(function(e) {
    	window.location="${h.url_for_www(controller='account', action='register')}";
    });

    $('#btnHelp').click(function(e) {
    	//window.location="${h.url_for_www(controller='account', action='help')}";
    });

    //<![CDATA[		
    //var so = new SWFObject("${h.url_for('/flash/banner.swf')}", "banner", "700", "120", "9");
    //so.useExpressInstall("${h.url_for('/flash/expressinstall.swf')}");
    //so.write("bannerWrapper");
    // ]]>
    
  });

  function showResponse(data, textStatus)  {
	  if (data.flag == 1) {
    	$('#signupWrapper').html(data.info);
	  } else {
		  var l = $('<label class="error">' + data.info + '</label>');
		  l.appendTo($('#errorWrapper'));
		  l.delay(3000, function() {
			  l.remove();
		  });
	  }
  }  
  	
  </script>	
</%def>
